// pages/mainVideo/mainVideo.js
import { getVideoList } from '../../service/request/video';
Page({
  data: {
    videoList: [],
    offset: 0,
    hasMore: true
  },
  onLoad() {
    this.fetchTopVideo(this.data.offset)
  },
  // 获取数据
  async fetchTopVideo(offset) {
    const res = await getVideoList(offset)
    const newList = [ ...this.data.videoList, ...res.data]
    this.setData({videoList: newList})
    this.data.offset = this.data.videoList.length
    this.data.hasMore = res.hasMore
  },
  // 上拉加载
  onReachBottom() {
    if (this.data.hasMore) {
      this.fetchTopVideo(this.data.offset)
    }
  },
  // 下拉刷新
  async onPullDownRefresh() {
    this.data.videoList = []
    this.data.offset = 0
    this.data.hasMore = true
    await this.fetchTopVideo()
    wx.stopPullDownRefresh()
  }
})